#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<queue>
#include<string.h>
using namespace std;
int arr[50][50] = { 0 };
void DFS(int* visted,int n,int index)
{
	for (int i = 0; i < n; i++)
	{
		if (arr[index][i] == 1 && visted[i] == 1)
		{
			visted[i] = 0;
			DFS(visted, n, i);
		}
	}
}
int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < n; j++)
		{
			cin >> arr[i][j];
		}
	}
	int visted[50] = { 0 };
	for (int i = 0; i < n; i++)
	{
		visted[i] = 1;
	}
	int sum = 0;
	for (int i = 0; i < n; i++)
	{
		if (visted[i] == 0)
			continue;
		else
		{
			visted[i] = 0;
			sum++;
		}
		for (int j = 0; j < n; j++)
		{
			if (arr[i][j] == 1)
			{
				if (visted[j] == 1)
				{
					visted[j] = 0;
					DFS(visted,n,j);
				}
			}
		}
	}
	cout << sum;
	return 0;
}